from datetime import datetime
import time


# 为空就是当前时间
def str2unix(time_str, format_str="%Y-%m-%d %H:%M:%S"):
    if time_str:
        date = datetime.strptime(time_str, format_str)
    else:
        date = datetime.now()
    unix_time = "{}000000000".format(int(time.mktime(date.timetuple())))
    return unix_time


def unix2str(unix, format_str="%Y-%m-%d %H:%M:%S"):
    unix_int = int(unix)
    time = datetime.fromtimestamp(unix_int)
    time_str = time.strftime(format_str)
    return time_str